package com.tmt.im.manager.config.beans;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.session.data.redis.config.annotation.web.http.RedisIndexedHttpSessionConfiguration;
import org.springframework.stereotype.Component;

import java.time.Duration;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/27 20:49
 * @Version 1.0
 **/
@Component
public class MyBeanPostProcessor implements BeanPostProcessor{

    @Value("${oauth2.token-expire-time:PT600S}")
    private Duration tokenExpireTime;

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        Object beanObj = BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);

        assert beanObj != null;
        if (bean instanceof RedisIndexedHttpSessionConfiguration redisSessionConfig) {
            redisSessionConfig.setMaxInactiveInterval(tokenExpireTime);
        }

        return beanObj;
    }

}
